package com.lock;

import java.util.concurrent.TimeUnit;

/**
 * @Author: sn
 * @Desc 测试notifyall之后等待队列的执行顺序
 * @Date: 2022/4/27
 */
public class TestWaitOrder {

    static  Object object = new Object();//锁对象

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {//jack
            synchronized (object){
                System.out.println(String.format("{%s}-没有香烟 我去等待老板安排 先休息，安排好之后叫醒我",Thread.currentThread().getName()));
                try {
                    //jack线程进入阻塞，但是释放了锁
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(String.format("{%s}-开始工作，大中华真不错",Thread.currentThread().getName()));
            }
        }, "jack").start();
        TimeUnit.SECONDS.sleep(1);


        TimeUnit.SECONDS.sleep(1);
        new Thread(() -> {
            synchronized (object){
                //log.debug("没有加钱，先休息不干活");
                System.out.println(String.format("{%s}-没有加钱，先休息不干活",Thread.currentThread().getName()));
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(String.format("{%s}-干活了----有钱能使鬼推",Thread.currentThread().getName()));
            }
        }, "rose").start();


    }
}
